<template>
  <div class="page-container">
	<!--工具栏-->
	<div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
		<el-form :inline="true" :model="filters" :size="size">
			<el-form-item>
				<el-input v-model="filters.zghzxm" placeholder="主管行长姓名"></el-input>
			</el-form-item>
			<el-form-item>
				<kt-button icon="fa fa-search" :label="$t('action.search')" perms="app:estate:view" type="primary" @click="findPage(null)"/>
			</el-form-item>
			<el-form-item>
				<kt-button icon="fa fa-plus" :label="$t('action.add')" perms="app:estate:add" type="primary" @click="handleAdd" />
			</el-form-item>
		</el-form>
	</div>
	<div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
		<el-form :inline="true" :size="size">
			<el-form-item>
				<el-button-group>
				<el-tooltip content="刷新" placement="top">
					<el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
				</el-tooltip>
				<el-tooltip content="列显示" placement="top">
					<el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
				</el-tooltip>
				</el-button-group>
			</el-form-item>
		</el-form>
		<!--表格显示列界面-->
		<table-column-filter-dialog ref="tableColumnFilterDialog" :columns="columns" 
			@handleFilterColumns="handleFilterColumns"> 
		</table-column-filter-dialog>
	</div>
	<!--表格内容栏-->
	<kt-table :height="350" permsEdit="app:estate:edit" permsDelete="app:estate:delete"
		:data="pageResult" :columns="filterColumns"
		@findPage="findPage" @handleEdit="handleEdit" @handleDelete="handleDelete">
	</kt-table>
	<!--新增编辑界面-->
	<el-dialog :title="operation?'新增':'编辑'" width="40%" :visible.sync="dialogVisible" :close-on-click-modal="false">
		<el-form :model="dataForm" label-width="150px" :rules="dataFormRules" ref="dataForm" :size="size" label-position="right">           
            <el-form-item label="ID" prop="id" v-if="false">
				<el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="主管行长身份证号" prop="zghzsfzh">
				<el-input v-model="dataForm.zghzsfzh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="主管行长姓名" prop="zghzxm">
				<el-input v-model="dataForm.zghzxm" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="主管行长电话" prop="zghzdh">
				<el-input v-model="dataForm.zghzdh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="抵押权人全称" prop="dyqrqc">
				<el-input v-model="dataForm.dyqrqc" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="机构代号" prop="jgdh">
				<el-input v-model="dataForm.jgdh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="联系电话" prop="lxdh">
				<el-input v-model="dataForm.lxdh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="通讯地址" prop="txdz">
				<el-input v-model="dataForm.txdz" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="营业执照代号" prop="yyzz">
				<el-input v-model="dataForm.yyzz" auto-complete="off"></el-input>
			</el-form-item>            
			<el-form-item label="对公账号" prop="dgzh">
				<el-input v-model="dataForm.dgzh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="对公联系电话" prop="dglxdh">
				<el-input v-model="dataForm.dglxdh" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="对私名称" prop="dsmc">
				<el-input v-model="dataForm.dsmc" auto-complete="off"></el-input>
			</el-form-item>
			<el-form-item label="对私联系电话" prop="dslxdh">
				<el-input v-model="dataForm.dslxdh" auto-complete="off"></el-input>
			</el-form-item>

		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button :size="size" @click.native="dialogVisible = false">{{$t('action.cancel')}}</el-button>
			<el-button :size="size" type="primary" @click.native="submitForm" :loading="editLoading">{{$t('action.submit')}}</el-button>
		</div>
	</el-dialog>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput"
import KtTable from "@/views/Core/KtTable"
import KtButton from "@/views/Core/KtButton"
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog"
import { format } from "@/utils/datetime"
export default {
	components:{
		PopupTreeInput,
		KtTable,
		KtButton,
		TableColumnFilterDialog
	},
	data() {
		return {
			size: 'small',
			filters: {
				zghzxm: ''
			},
			columns: [],
			filterColumns: [],
			pageRequest: { pageNum: 1, pageSize: 10 },
			pageResult: {},

			operation: false, // true:新增, false:编辑
			dialogVisible: false, // 新增编辑界面是否显示
			editLoading: false,
			dataFormRules: {
				zghzxm: [
					{ required: true, message: '请输入姓名', trigger: 'blur' }
				]
			},
			// 新增编辑界面数据
			dataForm: {
                id: '',
                zghzsfzh: '',
                zghzxm: '',
                zghzdh: '',
                dyqrqc: '',
                jgdh: '',
                lxdh: '',
                txdz: '',
                yyzz: '',
                dgzh: '',
                dglxdh: '',
                dsmc: '',
                dslxdh: ''
			}
		}
	},
	methods: {
		// 获取分页数据
		findPage: function (data) {
			if(data !== null) {
				this.pageRequest = data.pageRequest
			}
			this.pageRequest.columnFilters = {name: {name:'zghzxm', value:this.filters.zghzxm}}
			this.$api.dyqrgl.findPage(this.pageRequest).then((res) => {
				this.pageResult = res.data 
			}).then(data!=null?data.callback:'')
        },
        
		// 批量删除
		handleDelete: function (data) {
			this.$api.dyqrgl.batchDelete(data.params).then(data!=null?data.callback:'')
        },
        
		// 显示新增界面
		handleAdd: function () {
			this.dialogVisible = true
			this.operation = true
			this.dataForm = { 
                zghzsfzh: '1',
                zghzxm: '2',
                zghzdh: '3',
                dyqrqc: '4',
                jgdh: '5',
                lxdh: '6',
                txdz: '7',
                yyzz: '8',
                dgzh: '9',
                dglxdh: '10',
                dsmc: '11',
                dslxdh: '12'
			}
        },
        
		// 显示编辑界面
		handleEdit: function (params) {
			this.dialogVisible = true
			this.operation = false
			this.dataForm = Object.assign({}, params.row)
        },
        
		// 编辑
		submitForm: function () {
			this.$refs.dataForm.validate((valid) => {
				if (valid) {
					this.$confirm('确认提交吗？', '提示', {}).then(() => {
						this.editLoading = true
						let params = Object.assign({}, this.dataForm)
                        
						this.$api.dyqrgl.save(params).then((res) => {
							this.editLoading = false
							if(res.code == 200) {
								this.$message({ message: '操作成功', type: 'success' })
								this.dialogVisible = false
								this.$refs['dataForm'].resetFields()
							} else {
								this.$message({message: '操作失败, ' + res.msg, type: 'error'})
							}
							this.findPage(null)
						})
					})
				}
			})
		},
		 
		// 菜单树选中
      	deptTreeCurrentChangeHandle (data, node) {
        	// this.dataForm.deptId = data.id
        	// this.dataForm.deptName = data.name
		},
		// 时间格式化
      	dateFormat: function (row, column, cellValue, index){
          	return format(row[column.property])
      	},
		// 处理表格列过滤显示
      	displayFilterColumnsDialog: function () {
			this.$refs.tableColumnFilterDialog.setDialogVisible(true)
      	},
		// 处理表格列过滤显示
      	handleFilterColumns: function (data) {
			this.filterColumns = data.filterColumns
			this.$refs.tableColumnFilterDialog.setDialogVisible(false)
      	},
		// 处理表格列过滤显示
      	initColumns: function () {
			this.columns = [ 
				{prop:"zghzsfzh", label:"主管行长身份证号", minWidth:150},
				{prop:"zghzxm", label:"主管行长姓名", minWidth:120}, 
                {prop:"zghzdh", label:"主管行长电话", minWidth:120}, 
                {prop:"dyqrqc", label:"抵押权人全称", minWidth:120}, 
                {prop:"jgdh", label:"机构代号", minWidth:100}, 
                {prop:"lxdh", label:"联系电话", minWidth:100}, 
                {prop:"txdz", label:"通讯地址", minWidth:120}, 
                {prop:"yyzz", label:"营业执照代号", minWidth:120}, 
                {prop:"dgzh", label:"对公账号", minWidth:100}, 
                {prop:"dglxdh", label:"对公联系电话", minWidth:120}, 
                {prop:"dsmc", label:"对私名称", minWidth:100}, 
                {prop:"dslxdh", label:"对私联系电话", minWidth:120}
			]
			this.filterColumns = JSON.parse(JSON.stringify(this.columns));
      	}
	},
	mounted() { 
		this.initColumns()
	}
}
</script>

<style scoped>

</style>